package wanbangee.service.imp;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import wanbangee.dao.CarDao;
import wanbangee.dao.GoodsDao;
import wanbangee.dao.GoodsDetailDao;
import wanbangee.dao.GoodsTypeDao;
import wanbangee.entities.Car;
import wanbangee.entities.Goods;
import wanbangee.entities.GoodsDetail;
import wanbangee.entities.GoodsType;
import wanbangee.service.GoodsMangerService;
@Service
public class GoodsMangerServiceImp implements GoodsMangerService {
	@Autowired
	private GoodsTypeDao goodsTypeDao;
	@Autowired
	private GoodsDetailDao goodsDetailDao;
	@Autowired
	private GoodsDao goodsDao;
	@Autowired
	private CarDao carDao;
	@Override
	public List<GoodsType> selectAll() {
		// TODO Auto-generated method stub
		return this.goodsTypeDao.selectAll();
	}
	@Override
	public List<GoodsDetail> selectByGoodsId(Integer goodsTypeId) {
		// TODO Auto-generated method stub
		return this.goodsDetailDao.selectByGoodsId(goodsTypeId);
	}
	@Override
	public List<Goods> selectByGoodsNameLike(String goodLike) {
		// TODO Auto-generated method stub
		return this.goodsDao.selectByGoodsNameLike("%"+goodLike+"%");
	}
	@Override
	public List<Goods> selectByNewGoods() {
		// TODO Auto-generated method stub
		return this.goodsDao.selectByNewGoods();
	}
	@Override
	public List<Goods> selectByBest() {
		// TODO Auto-generated method stub
		List<Goods> goods = new ArrayList();
		for(Integer goodsId:this.goodsDao.selectByBest()) {
			Goods good = this.goodsDao.selectGoodsByGoodsId(goodsId);
			goods.add(good);
		}
		return goods;
	}
	@Override
	public List<Goods> selectByBestFromMouth() {
		// TODO Auto-generated method stub\
		List<Goods> goods = new ArrayList<Goods>();
        Date date =  new Date();
        Date strDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        strDate.setMonth(date.getMonth()-1);
        String endTime = sdf.format(date);
        String startTime = sdf.format(strDate);
        for(Integer goodsId :this.goodsDao.selectByBestFromMouth(startTime, endTime)) {
        	Goods good = this.goodsDao.selectGoodsByGoodsId(goodsId);
			goods.add(good);
        }
        return goods;
	}
	@Override
	public Double selectCarTotalPrice(Integer accountId) {
		// TODO Auto-generated method stub
		return this.carDao.selectCarTotalPrice(accountId);
	}
	@Override
	public List<Car> selectCar(Integer accountId) {
		// TODO Auto-generated method stub
		return this.carDao.selectCar(accountId);
	}
	@Override
	public Goods selectGoodsByGoodsId(Integer goodsId) {
		// TODO Auto-generated method stub
		return this.goodsDao.selectGoodsByGoodsId(goodsId);
	}

}
